package qumaimai.servlet.admin;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import qumaimai.dao.FundDao;
import qumaimai.dao.impl.FundDaoImpl;
import qumaimai.entity.Fund;
import qumaimai.entity.Goods;
import qumaimai.servlet.BaseServlet;

@WebServlet("/admin/AdminFundServlet")
public class AdminFundServlet extends BaseServlet{
	
	FundDao dao = new FundDaoImpl();
	
	public void findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		int page = Integer.parseInt(request.getParameter("page"));
		int size = Integer.parseInt(request.getParameter("limit"));
		List<Fund> list = dao.findCheck(page,size);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("count", dao.getCount());
		map.put("data", list);
		String json = JSON.toJSONString(map);
		response.getWriter().write(json);
	}
	
	public void check(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		int id = Integer.parseInt(request.getParameter("id"));
		double balance = dao.getBalance(id);
		int n = dao.confirm(id,balance);
		if(n>0){
			response.getWriter().write("success");
		}
	}

}
